package com.yixiang.np.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yixiang.np.mapper.NoticeMapperService;
import com.yixiang.np.model.Grid;
import com.yixiang.np.model.po.PltmNotice;
import com.yixiang.np.service.NoticeService;

/**
 * Created by Administrator on 2016/11/1.
 */
@Service("noticeService")
public class NoticeServiceImpl implements NoticeService  {
    private static final Logger LOG = LoggerFactory.getLogger(NoticeServiceImpl.class);

    @Resource
    private NoticeMapperService noticeMapperService;

    @Override
    public Grid noticePage(PltmNotice pltmNotice, Integer page, Integer rows) {
        Grid grid = new Grid();
        PageHelper.startPage(page, rows);
        List<PltmNotice> pltmNotices = noticeMapperService.listByCondition(pltmNotice, "create_time desc");
        LOG.debug("pltmNotices:{};", pltmNotices);
        PageInfo<PltmNotice> pltmNoticePageInfo = new PageInfo<>(pltmNotices);
        grid.setTotal(pltmNoticePageInfo.getTotal());
        grid.setRows(pltmNotices);
        return grid;
    }

    @Override
    public Integer create(PltmNotice pltmNotice) {
        Integer result = noticeMapperService.create(pltmNotice);
        LOG.debug("result:{};", result);
        return result;
    }

    @Override
    public Integer update(PltmNotice pltmNotice) {
        Integer result = noticeMapperService.updateById(pltmNotice);
        LOG.debug("result:{};", result);
        return result;
    }

    @Override
    public Integer delete(PltmNotice pltmNotice) {
        return noticeMapperService.delete(pltmNotice);
    }

    @Override
    public PltmNotice read(PltmNotice pltmNotice) {
        return noticeMapperService.read(pltmNotice);
    }
}
